package com.cliente;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import com.example.conver.R;
import com.google.gson.Gson;

import domain.AdministradorVO;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {


	Button login;
	TextView error;
	EditText user, pass;
	Controller C = new Controller();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		user = (EditText) findViewById(R.id.User);
		pass = (EditText) findViewById(R.id.Pass);
		error = (TextView) findViewById(R.id.Token);
		login = (Button) findViewById(R.id.Login);
		
		final Bundle b =this.getIntent().getExtras();
		
		String mostrar = "";
		try{
			mostrar =""+b.getString("response");
		}catch (Exception e) {}
		
		error.setText(mostrar);

		login.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				String result= C.logear(user.getText().toString(), pass.getText().toString());
				
				if(result.length()==20){
					Intent menu=new Intent(MainActivity.this, Menu.class);
					Bundle bundle=new Bundle();
					
					//compartir datos
					SharedPreferences prefs = getSharedPreferences("session", Context.MODE_PRIVATE);
					SharedPreferences.Editor editor = prefs.edit();
					editor.putString("TOKEN", ""+result);
					editor.commit();
					startActivity(menu);
					finish();
					}else{
					error.setText("Token: "+result);
					}
			}
		});
	}
}